home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Devices / CD-ROM / How to Detect a CD / Not used in this example / identifyCD.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-18  |  2.1 KB  |  87 lines  |  [TEXT/MPS ]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Sample code demonstrating detecting a CD
  5. **
  6. **    by Brian Bechtel, Apple Developer Technical Support
  7. **
  8. **    File:        identifyCD.c
  9. **
  10. **    Copyright © 1995 Apple Computer, Inc.
  11. **    All rights reserved.
  12. **
  13. **    You may incorporate this sample code into your applications without
  14. **    restriction, though the sample code has been provided "AS IS" and the
  15. **    responsibility for its operation is 100% yours.  However, what you are
  16. **    not permitted to do is to redistribute the source as "DTS Sample Code"
  17. **    after having made changes. If you're going to re-distribute the source,
  18. **    we require that you make it clear in the source that the code was
  19. **    descended from Apple Sample Code, but that you've made changes.
  20. */
  21.  
  22. #include <Devices.h>
  23. #include <Files.h>
  24. #include "identifyCD.h"
  25.  
  26. /* 
  27.  * use this version of a Control structure for a ReadTOC call
  28.  */
  29. typedef struct {
  30.     struct QElem *qLink;
  31.     short qType;
  32.     short ioTrap;
  33.     Ptr ioCmdAddr;
  34.     ProcPtr ioCompletion;
  35.     OSErr ioResult;
  36.     char *ioNamePtr;
  37.     short ioVRefNum;
  38.     short ioCRefNum;
  39.     short csCode;
  40.     unsigned long    discID;
  41.     char    unused[18];
  42. } CDTOCParam;
  43.  
  44. enum {
  45.     kReadTOC = 100
  46. };
  47.  
  48. /************************************************************************
  49.  *
  50.  *  Function:        IDDisc
  51.  *
  52.  *  Purpose:        return total time on this disc as unique ID
  53.  *
  54.  *  Returns:        OSErr
  55.  *                    either noErr if everything was okay
  56.  *                    or some parameter error from driver call.
  57.  *
  58.  *  Side Effects:
  59.  *                    fills in discID
  60.  *
  61.  *  Description:
  62.  *                    call the driver ReadTOC call to get lead-out time.
  63.  *                    Return this time as the unique id for this disc.
  64.  *
  65.  ************************************************************************/
  66. OSErr IDDisc(short refNum, unsigned long *discID)
  67. {
  68.     CDTOCParam    myPB;
  69.     OSErr    result;
  70.     
  71.     myPB.ioCompletion = 0;
  72.     myPB.ioNamePtr = (char *) 0;
  73.     myPB.ioVRefNum = 0;
  74.     myPB.ioCRefNum = refNum;
  75.     myPB.csCode = kReadTOC;
  76.     myPB.discID = 0x00020000;    /* request lead-out time */
  77.     
  78.     result = PBControlSync((ParmBlkPtr)&myPB);
  79.     
  80.     if (result == noErr)
  81.         *discID = myPB.discID >> 8;
  82.     else
  83.         *discID = 0;
  84.     return result;
  85. }
  86.  
  87.